package org.gap.wizards.items;

import org.gap.wizards.effects.Effect;
import org.gap.wizards.utils.Persistence;
import org.gap.wizards.views.ViewPlatform;
import org.gap.wizards.views.ViewPlatform.Color;

public class Money extends Item {
	private int count;

	public Money(int count) {
		super(Effect.NONE, new Description("Money", '$', Color.YELLOW));
		this.count = count;
	}
	
	public Money() {
		this(0);
	}

	@Override
	public void draw(ViewPlatform console, int x, int y) {
		console.print(x, y, Color.YELLOW, "$");
	}

	public Money add(Money item) {
		return new Money(count + item.count);
	}

	public int getAmount() {
		return count;
	}

	@Override
	public void persist(Persistence writer) {
		writer.set("count", count);
	}
	
	@Override
	public void load(Persistence value) {
		count = value.getInt("count");
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj.getClass().equals(Money.class)) {
			Money other = (Money) obj;
			return getAmount() == other.getAmount();
		}
		return false;
	}
}
